package com.link.ppt.View;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.link.ppt.App.App;
import com.link.ppt.Base.BaseActivity;
import com.link.ppt.Consts.Constants;
import com.link.ppt.Model.Bean.BaseBean;
import com.link.ppt.Model.Bean.PersonalInfoBean;
import com.link.ppt.Model.IUserModel;
import com.link.ppt.Model.Impl.UserModelImpl;
import com.link.ppt.R;
import com.link.ppt.Utils.CommonSubscriber;
import com.link.ppt.Utils.GlideUtils;
import com.link.ppt.Utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import rx.functions.Action0;

/**
 * 个人信息画面
 * Created by liuch on 2018/1/24.
 */

public class PersonalInfoActivity extends BaseActivity {

    @BindView(R.id.layout_ppt_stars)
    RelativeLayout layout_ppt_stars;
    @BindView(R.id.layout_ppt_publishs)
    RelativeLayout layout_ppt_publishs;

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.layout_back)
    LinearLayout layout_back;
    @BindView(R.id.imv_user_header)
    CircleImageView imv_user_header;
    @BindView(R.id.tv_user_name)
    TextView tv_user_name;

    private String avaster_url="";

    private IUserModel model;

    @Override
    public int getLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    public void setupView() {
        ButterKnife.bind(this);
        tv_title.setText("");
        layout_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                App.GetInstance().finishActivity(PersonalInfoActivity.this);
            }
        });
        model = new UserModelImpl();
    }

    @Override
    public void setupData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        model.RequestUserInfo().doOnSubscribe(new Action0() {
            @Override
            public void call() {
//                showProgress();
            }
        }).subscribe(new CommonSubscriber<PersonalInfoBean>() {
            @Override
            public void onSuccess(PersonalInfoBean response) {
//                hideProgress();
                initViews(response);
            }

            @Override
            public void onFailure(BaseBean response) {
//                hideProgress();
                ToastUtils.showShortToast(PersonalInfoActivity.this, response.getDesc());
            }
        });
    }

    @OnClick({R.id.layout_ppt_stars, R.id.layout_ppt_publishs, R.id.imv_user_header})
    void doClicks(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.layout_ppt_stars:
                Intent intent = new Intent(PersonalInfoActivity.this, StorePublishActivity.class);
                intent.putExtra("isMyPublishPPT", false);
                startActivity(intent);
                break;
            case R.id.layout_ppt_publishs:
                Intent intent2 = new Intent(PersonalInfoActivity.this, StorePublishActivity.class);
                intent2.putExtra("isMyPublishPPT", true);
                startActivity(intent2);
                break;
            case R.id.imv_user_header:
                Intent intent1 = new Intent(PersonalInfoActivity.this, EditPersonalInfoActivity.class);
                intent1.putExtra("user_name", tv_user_name.getText().toString());
                intent1.putExtra("user_avaster_url",avaster_url);
                startActivity(intent1);
                break;
        }
    }

    private void initViews(PersonalInfoBean info) {
        GlideUtils.getInstance().loadSimpleContextVitMap(this, Constants.BASE_URL + info.getHeadImgUrl(), imv_user_header);
        tv_user_name.setText(info.getTrueName());
        avaster_url=Constants.BASE_URL + info.getHeadImgUrl();
    }
}
